<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="utf-8">
	<title>管理员日志</title>
	<meta name="renderer" content="webkit">
	<meta name="referrer" content="never">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../assets/lib/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="../assets/css/public.css" media="all">
</head>

<body>
	<div class="admin-container">
		<div class="admin-main">
			<fieldset class="table-search-fieldset">
				<legend>搜索信息</legend>
				<form class="layui-form" lay-filter="search">
					<div class="layui-form-item">
						<div class="layui-inline">
							<input type="text" name="aid" maxlength="30" placeholder="管理员" lay-verify="" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-inline">
							<input type="text" name="module" maxlength="30" placeholder="模块" lay-verify="" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-inline">
							<input type="text" name="action" maxlength="4" placeholder="操作内容" lay-verify="zh" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-inline">
							<input type="text" name="time" placeholder="记录时间" lay-verify="datetime" autocomplete="off" class="layui-input" readonly>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="search-submit" style="display: flex;"><i class="layui-icon layui-icon-search"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</fieldset>
			<table class="layui-table" id="log-list" lay-filter="log-list"></table>
		</div>
	</div>
	<script src="../assets/lib/layui/layui.js" charset="utf-8"></script>
	<script src="../assets/js/lay-config.js" charset="utf-8"></script>
	<script src="../assets/js/public.min.js" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use(['jquery', 'form', 'table', 'laydate', 'selectN'], function() {
			var $ = layui.jquery,
				form = layui.form,
				table = layui.table,
				laydate = layui.laydate;

			laydate.render({
				elem: $('.layui-form [name="time"]')[0],
				type: 'datetime',
				trigger: 'click'
			});

			var tableIns = table.render({
				elem: '#log-list',
				url: lianyi.api('log_list', 1),
				method: 'POST',
				toolbar: 'default',
				defaultToolbar: ['filter', 'print', 'exports'],
				limits: [50, 100, 200, 300, 500],
				limit: 50,
				page: true,
				cols: [
					[
						{ type: "checkbox", fixed: 'left' },
						{ type: "numbers", title: '序号' },
						{ field: 'name', width: 90, title: '管理员', event: 'name', sort: true },
						{ field: 'module', minWidth: 90, title: '模块', event: 'module', sort: true },
						{ field: 'action', minWidth: 105, title: '操作内容', event: 'action' },
						{ field: 'ip', width: 130, title: 'IP地址', align: 'center', sort: true },
						{ field: 'time', width: 160, title: '记录时间', sort: true },
						{
							title: '操作',
							width: 65,
							align: 'center',
							fixed: 'right',
							templet: function(d) {
								return '<div class="layui-btn-group">' +
									'<button type="button" lay-event="delete" class="layui-btn layui-btn-xs layui-btn-danger" tips="删除"><i class="layui-icon layui-icon-delete" style="margin-right: 0px;"></i></button>' +
									'</div>';
							}
						}
					]
				],
				done: function(d) {
					tableIns.config.page.count = d.count;
					$('.layui-table-tool [lay-event="update"]').hide();
					$('.layui-table-tool [lay-event="add"]').hide();
				}
			});

			table.on('toolbar(log-list)', function(obj) {
				var event = obj.event;
				switch (event) {
					case 'delete':
						var checkStatus = table.checkStatus(obj.config.id);
						var data = checkStatus.data,
							ids = [];

						$.each(data, function(i, v) {
							ids.push(v.id);
						});

						layer.confirm('确定' + (ids.length > 0 ? '删除已选<b style="color: #ff0000;">' + ids.length + '</b>条' : '<b style="color: #ff0000;">清空</b>') + '日志？', {
							title: '删除管理员日志',
							shadeClose: true,
							btn: ['删除', '取消'],
							btn1: function(index) {
								lianyi.request({
									url: lianyi.api('delete', 1),
									data: ids.length > 0 ? { id: ids.join(',') } : {},
									msg: '正在删除...',
									success: function(res) {
										tableIns.reload({
											page: {
												curr: 1
											}
										});
										layer.close(index);
									}
								});
								return false;
							}
						});
						break;
				}
			});

			table.on('tool(log-list)', function(obj) {
				var data = obj.data,
					event = obj.event;

				switch (event) {
					case 'name':
						layer.prompt({
								title: '管理员',
								formType: 2,
								shadeClose: true,
								allowBlank: true,
								maxlength: 30,
								value: '用户名：' + data.user + '\n姓名：' + (data.name || ''),
								btn: ['关闭'],
								success: function(elem) {

								}
							},
							function(value, index, elem) {
								layer.close(index);
							}
						);
						break;
					case 'module':
						layer.prompt({
								title: '模块',
								formType: 2,
								shadeClose: true,
								allowBlank: true,
								maxlength: 30,
								value: data.module,
								btn: ['关闭'],
								success: function(elem) {

								}
							},
							function(value, index, elem) {
								layer.close(index);
							}
						);
						break;
					case 'action':
						layer.prompt({
								title: '具体操作',
								formType: 2,
								shadeClose: true,
								allowBlank: true,
								maxlength: 30,
								value: data.action,
								btn: ['关闭'],
								success: function(elem) {

								}
							},
							function(value, index, elem) {
								layer.close(index);
							}
						);
						break;
					case 'delete':
						var page = tableIns.config.page;

						layer.confirm('确定删除这条日志？', {
							title: '删除管理员日志',
							shadeClose: true,
							btn: ['删除', '取消'],
							btn1: function(index) {
								lianyi.request({
									url: lianyi.api('delete', 1),
									data: { id: data.id },
									msg: '正在删除...',
									success: function(res) {
										tableIns.reload({
											page: {
												curr: Math.ceil((page.count - 1) / page.limit)
											}
										});
										layer.close(index);
									}
								});
								return false;
							}
						});
						break;
				}
			});

			form.on('submit(search-submit)', function(obj) {
				var field = obj.field;

				tableIns.reload({
					page: {
						curr: 1
					},
					where: field
				});

				return false;
			});
		});
	</script>
</body>

</html>